package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/06 21:21
 **/
public class Day4_9_Offer63_MaxProfit {
    class Solution {
        public int maxProfit(int[] prices) {
            if(prices == null ||  prices.length <= 1) return 0;
            int ans = 0, min = prices[0];
            for(int i = 1; i < prices.length; ++i){
                if(prices[i] < min) {

                    min = prices[i];
                }else {
                    ans = Math.max(ans, prices[i] - min);
                }
            }
            return ans;
        }
    }
}